import React from "react";
import { Button, Form, Input, Notify } from "react-vant";
import axios from 'axios'
import { useNavigate } from "react-router-dom";
const Login = () => {
  const navigate = useNavigate()
  const onFinish = async (values) => {
    // 请求数据 
    const resp = await axios.post('/api/login', values);
    const { code, message } = resp.data
    if(code === 200) {
      // 进入首页
      navigate('/')
      Notify.show({ type: 'success', message })
    } else {
      // 友好提示
      Notify.show({ type: "danger", message })
      
    }

  };
  return (
    <div>
      <h2>用户登陆</h2>
      <Form
        onFinish={onFinish}
        footer={
          <div>
            <Button type="primary" block round nativeType="submit">
              登陆
            </Button>
          </div>
        }
      >
        <Form.Item label="账号" name="username">
          <Input></Input>
        </Form.Item>
        <Form.Item label="密码" name="password">
          <Input></Input>
        </Form.Item>
      </Form>
    </div>
  );
};

export default Login;
